<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="挂号id" prop="RegisterId">
        <el-input
          v-model="queryParams.RegisterId"
          clearable
          placeholder="请输入挂号id"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="ItemId">
        <el-input
          v-model="queryParams.ItemId"
          clearable
          placeholder="请输入项目名称"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="缴费状态" prop="State">
        <el-select v-model="queryParams.State" clearable placeholder="请选择缴费状态">
          <el-option
            v-for="dict in dict.type.payment_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="PatientCostsList">
      <el-table-column align="center" label="id" prop="Id"/>
      <el-table-column align="center" label="挂号id" prop="RegisterId"/>
      <el-table-column align="center" label="项目名称" prop="ItemId">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cost_type" :value="scope.row.ItemId"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="项目价格" prop="Price"/>
      <el-table-column align="center" label="缴费状态" prop="State">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.payment_state" :value="scope.row.State"/>
        </template>
      </el-table-column>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:PatientCosts:edit']"
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleCosts(scope.row)"
          >缴费
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.size"
      :page.sync="queryParams.current"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {getPaid, listPatientCosts,} from "@/api/system/PatientCosts";

export default {
  name: "PatientCostsService",
  dicts: ['payment_state', 'cost_type'],
  data() {
    return {
      loading: true,
      showSearch: true,
      total: 0,
      PatientCostsList: [],
      queryParams: {
        current: 1,
        size: 10,
        RegisterId: null,
        ItemId: null,
        State: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listPatientCosts(this.queryParams).then(response => {
        this.PatientCostsList = response.records;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCosts(row) {
      this.$confirm("确定缴费此项目吗？", {
        beforeClose: (action, ctx, close) => {
          if (action !== 'confirm') {
            close();
            return;
          }
          ctx.confirmButtonLoading = true;
          ctx.confirmButtonText = "缴费中";
          setTimeout(() => {
            getPaid(row.Id).then(() => {
              ctx.confirmButtonLoading = false;
              this.$msgbox.close();
              this.$modal.msgSuccess("缴费成功");
              this.getList();
            })
          }, 2000)
        }
      })
    },
  }
};
</script>
